<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<legend><span>查询条件</span></legend>
			<div id="queryForm" class="fieldset-body">
				<table class="form-table" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="form-label">
							<span>角色名称：</span>
							<input name="roleName" class="mini-textbox" style="width: 150px" />
							<input name="roleName_link" value="like" class="mini-hidden" style="width: 150px" />
							<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
						</td>
					</tr>
				</table>
			</div>
		</fieldset>

		<a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
		<a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
		<a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>

		</div>

		<div class="mini-fit">
			<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" idField="instID" allowResize="true">
				<div property="columns">
					<div type="indexcolumn"></div>
					<div field="roleID" visible="false"></div>
					<div field="roleName" headerAlign="center" allowSort="true">角色名称</div>
					<div field="description" headerAlign="center" allowSort="true">角色描述</div>
				</div>
			</div>
		</div>

		<div id="detailWin" class="mini-window" title="" style="width:500px;height:250px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div id="detailForm" style="padding:10px;">
				<input class="mini-hidden" name="factorId">
				<table align="center">
					<tr>
						<td align="right">角色编号：</td>
						<td align="left"><input id="roleID" name="roleID" class="mini-textbox" required="true"></td>
						<td align="right">角色名称：</td>
						<td align="left"><input name="roleName" class="mini-textbox" required="true"></td>
					</tr>
					<tr>
						<td align="right">角色描述：</td>
						<td align="left"><input name="description" class="mini-textbox" /></td>
						<td align="right"></td>
						<td align="left"></td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" onClick="save()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		miniInit();
	
		var queryForm = new mini.Form("#queryForm");
		var form = new mini.Form("#detailForm");
		var win = mini.get("detailWin");

		var datagrid = mini.get("datagrid");
		datagrid.set({
			url: http.getUrl("/role/list.do")
		});

		// 表单与表格绑定数据
		var db = new mini.DataBinding();
		db.bindForm("detailForm", datagrid);

		search();

		function search() {
			var data = queryForm.getData(true, false);
			datagrid.load(data, null, miniui.showLoadErrorMessageBox);
		}

		// 新增
		function add() {
			datagrid.clearSelect(false);
			form.reset();
			win.setTitle("新增角色");
			win.showAtPos('center', 'middle');
			mini.get("roleID").setEnabled(true);
		}

		// 修改
		function edit() {
			if(datagrid.getSelected()) {
				win.setTitle("修改角色数据");
				win.showAtPos('center', 'middle');
				mini.get("roleID").setEnabled(false);
			} else {
				mini.alert("请选中需要修改的数据行", "提示", null);
			}
		}
		// 保存污染物
		function save() {
			if(!form.validate()) {
				return;
			}
			mini.mask({
				el: document.body,
				cls: 'mini-mask-loading',
				html: '数据保存中...'
			});
			var data = form.getData();
			http.post(http.getUrl("/role/save.do"), data, function(page) {
				mini.unmask();
				win.hide();
				mini.alert("保存成功", "提示", null);
				datagrid.reload();
			});
		}

		function cancel() {
			win.hide();
		}

		// 删除用户
		function remove() {
			if(datagrid.getSelected() == null) {
				mini.alert("请选中需要删除的数据行", "提示", null);
				return;
			}

			mini.confirm("确认删除该数据信息吗？", "删除操作", function(e) {
				if(e == "ok") {
					mini.mask({
						el: document.body,
						cls: 'mini-mask-loading',
						html: '数据删除中...'
					});
					var ids = datagrid.getSelected().roleID;
					var data = {
						"roleID": ids
					};
					data.tableName = tableName;
					http.post("/role/delete.do", data, function(page) {
						mini.unmask();
						win.hide();
						mini.alert("删除成功", "提示", null);
						datagrid.reload();
					});
				}
			});
		}
	</script>

</html>